<?php defined('SYSPATH') or die('No direct script access.');

/**
 * @file privilege.php
 * @brief 
 * @author Lionel Tsai
 * @version 1.0
 * @date 2012-07-24
 */

define('PRIVILEGE_CUSGET', 0);

class Model_Privilege extends ORM {
	protected $_table_name = 'privilege';
	protected $_primary_key = 'info_id';
	protected $_belongs_to = array(
		'bank' => array('model'=>'bank', 'foreign_key' => 'bank_id'),
		//'province' => array('model'=>'type', 'foreign_key' => 'province_id'),
		//'city' => array('model'=>'type', 'foreign_key' => 'city_id'),
		'pri_project' => array('model'=>'term', 'foreign_key' => 'priproj_id'),
		'pri_type' => array('model'=>'term', 'foreign_key' => 'type_id'),
		'appscope_area' => array('model'=>'term', 'foreign_key' => 'appscope'),
	);
	protected $_has_many = array(
	);


	function as_array($type = 0) {
	 $ret = array();
	 switch($type) {
	 case PRIVILEGE_CUSGET:
		$ret = parent::as_array();
		break;
	 default:
		$ret = parent::as_array();
		//get bank name
		if($this->bank->loaded()) {
			$ret['bank_name'] = $this->bank->brief_name;	
			$ret['bank_tel'] = $this->bank->telephone;
			$ret['bank_website'] = $this->bank->website;
			$ret['bank_csemail'] = $this->bank->cs_email;
			$ret['bank_fax'] = $this->bank->fax;
			$ret['bank_zipcode'] = $this->bank->zipcode;
		}
		//
		if($this->pri_project->loaded()) {
			$ret['privilege_project_name'] = $this->pri_project->name;
		}
		if($this->pri_type->loaded()){
			$ret['privilege_type_name'] = $this->pri_type->name;			
		}
		if($this->appscope_area->loaded()){
			$ret['privilege_appscope_name'] = $this->appscope_area->name;
		}

		if($ret['if_icondefault']=='1') {
			$ret['icon_smallfull'] = 'default.png';
		}
		$pinyin = new Tool_Pinyinparse(); 
		$ret['province_pinyin'] = $pinyin->Pinyin($ret['privilege_appscope_name'], 2);
		$ret['detailcont'] = '';
	   break;	
		
	 }
	 return $ret;
	}

}
